import { getLookList } from '@/services/supplymanage';

export default {
  state: {
    pageData: {
      list: [],
      pagination: {
        current: 1,
        pageSize: 10,
        total: 10,
      },
    },
    formFieldsValue: {},
  },
  effects: {
    // 获取业务范围查看列表
    *getPageList({ payload }, { call, put }) {
      const response = yield call(getLookList, payload);
      const {
        pageArg: { currentPage, pageSize },
      } = payload;
      if (response.success) {
        yield put({
          type: 'getPageLookList',
          payload: {
            data: response.data,
            currentPage,
            pageSize,
          },
        });
      }
    },
  },
  reducers: {
    // 获取业务范围查看列表
    getPageLookList(
      state,
      {
        payload: { data, currentPage, pageSize },
      }
    ) {
      const list = Array.isArray(data.pageRecords) ? data.pageRecords : [];
      // eslint-disable-next-line array-callback-return
      return {
        ...state,
        pageData: {
          list,
          pagination: { total: data.totalCount, current: currentPage, pageSize },
        },
      };
    },
    // 设置修改当前state数据
    updateModelData(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    // 设置页签状态
    updateTabListQuery(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
